//
//  LoginViewController.m
//  TestYoho
//
//  Created by YiDarren on 17/2/3.
//  Copyright © 2017年 YiDarren. All rights reserved.
//

#import "LoginViewController.h"
#import "MBProgressHUD+JDragon.h"
#import "UITextField+placeHolder.h"
#import "MineViewController.h"


@interface LoginViewController ()<UITextFieldDelegate,UIScrollViewDelegate>

@property (weak, nonatomic) IBOutlet UIView *textFieldBgView;
@property (weak, nonatomic) IBOutlet UITextField *nameText;
@property (weak, nonatomic) IBOutlet UITextField *keyText;
@property (weak, nonatomic) IBOutlet UIScrollView *scrollView;

@end

@implementation LoginViewController


-(void)viewDidLoad {
    
    [super viewDidLoad];
    
    _textFieldBgView.layer.cornerRadius = 5;
    _textFieldBgView.clipsToBounds = YES;
    _textFieldBgView.layer.borderColor = [UIColor whiteColor].CGColor;
    _textFieldBgView.layer.borderWidth = 0.7;
    _loginBtn.layer.cornerRadius = 5;
    _loginBtn.layer.masksToBounds = YES;
    
    
    /**
     通过attributedPlaceholder可以对textField的占位文字进行颜色设置
     */
    
    
//    _nameText.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"请输入手机号"
//                                                                      attributes:@{
//                                                                                   NSForegroundColorAttributeName: [UIColor redColor],
//                                                                                   NSFontAttributeName : [UIFont systemFontOfSize:14]
//                                                                                   }


//    _keyText.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"设置密码"
//                                                                      attributes:@{
//                                                                                   NSForegroundColorAttributeName: [UIColor redColor],
//                                                                                   NSFontAttributeName : [UIFont systemFontOfSize:14]
//                                                                                   }
//                                       ];
}

-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
    
    if (textField == _nameText) {
        
        textField.placeholder = @"请输入手机号";
        textField.placeholderColor = [UIColor whiteColor];
        self.keyText.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"设置密码"
                                                                             attributes:@{
                                                                                          NSForegroundColorAttributeName: [UIColor lightGrayColor],
                                                                                          NSFontAttributeName : [UIFont systemFontOfSize:14]
                                                                                          }
                                              ];

    }
    else if (textField == _keyText) {
        
        textField.placeholder = @"设置密码";
        textField.placeholderColor = [UIColor whiteColor];

        self.nameText.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"请输入手机号"
                                                                              attributes:@{
                                                                                           NSForegroundColorAttributeName: [UIColor lightGrayColor],
                                                                                           NSFontAttributeName : [UIFont systemFontOfSize:14]
                                                                                           }
                                               ];

    }
    
    return YES;
}

-(BOOL)textFieldShouldReturn:(UITextField *)textField {
    
    return YES;
}

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    
    if ([_nameText isFirstResponder]) {
        
        [_nameText resignFirstResponder];
    }
    else if ([_keyText isFirstResponder]) {
        
        [_keyText resignFirstResponder];
    }
}

-(void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    
    if ([_nameText isFirstResponder]) {
        
        [_nameText resignFirstResponder];
    }
    else if ([_keyText isFirstResponder]) {
        
        [_keyText resignFirstResponder];
    }
}


- (IBAction)loginBtnAction:(id)sender {
    
    [MBProgressHUD showSuccessMessage:@"登录成功"];
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.75 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        
        [MBProgressHUD hideHUD];
        
        [self dismissViewControllerAnimated:YES completion:^{
            
        }];
        
    });
}


- (IBAction)closeBtnAction:(id)sender {
    
    [self dismissViewControllerAnimated:YES completion:^{
    
    }];
}

- (IBAction)loadOrRegistBtnAction:(id)sender {
    
    [MBProgressHUD showActivityMessageInWindow:@"注册账号"];

    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        
        [MBProgressHUD hideHUD];
    });
}




@end
